<?php

namespace plugin\seckill\app\api\controller;

use app\ApiController;
use plugin\seckill\app\api\service\OrderService;
use plugin\seckill\app\api\service\SeckillService;

class IndexController extends ApiController
{
    /**
     * 秒杀商品列表
     */
    public function index()
    {
        $param = request()->all();
        $seckillService = new SeckillService();
        return sparkSuccess($seckillService->getSeckillList($param));
    }

    /**
     * 秒杀商品详情
     */
    public function detail()
    {
        $seckillId = request()->input('seckill_id');

        $seckillService = new SeckillService();
        return sparkSuccess($seckillService->seckillDetail($seckillId));
    }

    /**
     * 秒杀订单商品信息
     */
    public function goodsInfo()
    {
        $param = request()->post();

        $orderService = new OrderService();
        return sparkSuccess($orderService->seckillGoodsInfo($param));
    }

    /**
     * 订单试算
     */
    public function trail()
    {
        $param = request()->post();
        $orderService = new OrderService();
        return sparkSuccess($orderService->trail($param, 1));
    }

    /**
     * 创建订单
     */
    public function createOrder()
    {
        $param = request()->post();
        $param['platform'] = '';
        $orderService = new OrderService();
        return sparkSuccess($orderService->createorder($param, 1));
    }

}
